home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1994 November / Cd Ware (Nro. 2) - Epimundo.iso / DOS / PG / GETNOTES.ZIP / GETNOTES.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-23  |  2.4 KB  |  108 lines

  1. /*  GETNOTES.C:
  2.       Read the notes from a BC++ 3.1 or TC++ 3.0 project file
  3.       and create a .not text file with those notes.
  4.     EDJ 05-23-94
  5. */
  6. #include  <alloc.h>
  7. #include  <dir.h>
  8. #include  <fcntl.h>
  9. #include  <io.h>
  10. #include  <process.h>
  11. #include  <stdio.h>
  12. #include  <string.h>
  13. #include  <sys\stat.h>
  14.  
  15. //  TC++ 3.0 and BC++ 3.1 project version.
  16. //
  17. #define PROJECT_VERSION 0x0701
  18.  
  19. //  Offset into project file where version can be found.
  20. //
  21. #define VERSION_OFFSET  0x1E
  22.  
  23. //  Signature of the notes block.
  24. //
  25. #define NOTE_HEADER     0x34
  26.  
  27.  
  28. int main( int argc, char **argv )
  29. {
  30.   int   inhandle,
  31.         outhandle,
  32.         versionNo,
  33.         blockType,
  34.         blockSize,
  35.         bytesRead;
  36.   char  exename[9]  = {'\0'},
  37.         notname[13] = {'\0'},
  38.         dontcare[120],
  39.         *noteChunk  = 0;
  40.  
  41.  
  42.   fnsplit( argv[0], dontcare, dontcare, exename, dontcare );
  43.  
  44.   if( argc < 2 )
  45.   {
  46.     printf( "Usage: %s <project file>\n", exename );
  47.     exit( -1 );
  48.   }
  49.  
  50.   inhandle  = open( argv[1], O_RDONLY | O_BINARY );
  51.   if( inhandle < 0 )
  52.   {
  53.     printf( "Unable to open %s.\n", argv[1] );
  54.     exit( -1 );
  55.   }
  56.  
  57.   fnsplit( argv[1], dontcare, dontcare, notname, dontcare );
  58.   strcat( notname, ".NOT");
  59.   outhandle = open( notname, O_WRONLY | O_BINARY | O_CREAT,
  60.     S_IREAD | S_IWRITE );
  61.  
  62.   if( inhandle < 0 )
  63.   {
  64.     printf( "Unable to open %s.\n", notname );
  65.     exit( -1 );
  66.   }
  67.  
  68.   lseek( inhandle, (long) VERSION_OFFSET, SEEK_SET );
  69.   read( inhandle, &versionNo, sizeof( int ));
  70.  
  71.   if( versionNo != PROJECT_VERSION )
  72.   {
  73.     printf( "Wrong project version (%4X)\n", versionNo );
  74.     exit( -1 );
  75.   }
  76.   
  77.   bytesRead = read( inhandle, &blockType, sizeof( int));
  78.   while( (blockType != NOTE_HEADER) && (bytesRead != 0))
  79.   {
  80.     read( inhandle, &blockSize, sizeof( int ));
  81.     lseek( inhandle, (long) blockSize, SEEK_CUR );
  82.     bytesRead = read( inhandle, &blockType, sizeof( int));
  83.   }
  84.  
  85.   if( bytesRead == 0 )
  86.   {
  87.     printf( "No project notes found in %s\n", argv[1] );
  88.     exit( 0 );
  89.   }
  90.  
  91.   read( inhandle, &blockSize, sizeof( int ));
  92.   noteChunk = (char *) malloc( blockSize );
  93.   if( !noteChunk )
  94.   {
  95.     printf( "Couldn't allocate %d bytes for notes!\n", blockSize );
  96.     exit( -1 );
  97.   }
  98.  
  99.   bytesRead = read( inhandle, noteChunk, blockSize );
  100.   write( outhandle, noteChunk, bytesRead );
  101.  
  102.   free( noteChunk );
  103.   close( inhandle );
  104.   close( outhandle );
  105.     
  106.   return 0;
  107. }
  108.